package com.enniswu.weitter.user.start;


import android.content.Context;
import android.view.View;
import android.widget.EditText;

import com.enniswu.weitter.R;
import com.enniswu.weitter.base.BaseFragment;

import butterknife.BindView;
import butterknife.OnClick;

public class LoginFragment extends BaseFragment<StartContract.Presenter> implements StartContract.View {

    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.et_psw)
    EditText etPassword;
    private StartFragmentListener listener;

    @Override
    protected int setContentView() {
        return R.layout.fragment_login;
    }

    @Override
    protected void onCreateView(View contentView) {
        presenter = new StartPresenter(this);
    }

    @Override
    public void next(int id) {
        if (getActivity() == null)
            return;
        getActivity().finish();
    }

    @OnClick(R.id.tv_register)
    public void toRegister() {
        listener.changeItem(2);
    }

    @OnClick(R.id.bt_login)
    public void login() {
        presenter.login(etPhone.getText().toString(), etPassword.getText().toString());
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof StartFragmentListener) {
            listener = (StartFragmentListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " 必须实现 StartFragmentListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        listener = null;
    }
}
